<?php
/**
 * Created by PhpStorm.
 * User: user1
 * Date: 2019-06-05
 * Time: 17:02
 */

namespace App\Common;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

class LogUtil
{
    public static function info($file, $content, $f = '', $line = '') {
        if (is_array($content)) {
            $content = json_encode($content, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        }
        $name = $f . ':' . $line;
        if ($name == ':') {
            $name = '';
        }
        $log = new Logger($name);
        $path = storage_path() . '/logs/' . date('Y-m-d');
        if (!file_exists($path)) {
            @mkdir($path, 0777, true);
            chmod($path, 0777);
        }
        $log_file = $path . '/' . $file . '.log';
        if (!file_exists($log_file)) {
            touch($log_file);
            chmod($log_file, 0777);
        }
        $log->pushHandler(new StreamHandler($log_file));
        //$log->addInfo($content);   //旧版本使用
        $log->info($content);
    }
}
